home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5979 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: frco.com!usenet
  2. From: Jadam@tcmail.frco.com (Jim Adam)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: inherited classes / functions
  5. Date: 7 Feb 1996 19:32:33 GMT
  6. Organization: Fisher Rosemount Systems
  7. Message-ID: <4fauoh$im2@rolaids.frco.com>
  8. References: <Pine.A32.3.91.960202182844.45749A-100000@asterix.uni-muenster.de>
  9. NNTP-Posting-Host: primrose.frco.com
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.11
  12.  
  13. In article 
  14. <Pine.A32.3.91.960202182844.45749A-100000@asterix.uni-muenster.de>, 
  15. kutzeln@uni-muenster.de says...
  16.  
  17. >when using inherited virtual functions, how can I simply call the
  18. >"inherited" function without knowing the name of the parent class? 
  19. >
  20. > While I am developing a graphical user interface, I sometimes need to 
  21. >"insert" a class in the class hierarchy, so I don't want to change all 
  22. > the "subclasses" code when "inserting" the new class. In Turbo Pascal 
  23. > there was the keyword "inherited" 
  24.  
  25. The suggested approach (see _The Design and Evolution of C++_, B.
  26. Stroustrup, Section 13.6) is:
  27.  
  28.   class foreman : public employee {
  29.     typedef employee inherited;
  30.   };
  31.  
  32.   class manager : public foreman {
  33.     typedef foreman inherited;
  34.   };
  35.  
  36.   // ETC.
  37.  
  38. Then, rather than:
  39.   
  40.   int manager::doSomething()  {
  41.     return foreman::doSomething();
  42.   }
  43.  
  44. you say
  45.  
  46.   int manager::doSomething() {
  47.     return inherited::doSomething();
  48.   }
  49.  
  50. Note, I've also seen people use "typedef foreman Base" and
  51. other things rather than "inherited."  --Anyway, this keeps
  52. the implementation of the derived classes from having to
  53. change.  Only the definition part has to change.
  54.  
  55. Jim
  56.  
  57.  
  58.  
  59.